package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qxfw.rcyw.pojo.JobMake;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/3  星期一   14:32
 * @description : 此类用来 排班管理 的底层数据交互
 ***************************************/
@Mapper
@DS("service")
public interface WorkforceManagementMapper extends BaseMapper<JobMake> {

    @Select("select distinct nametype from job_make")
    List<JobMake> selectJobType();

    @Select("<script>" +
            "select id,jobname,nametype,recentmaketime " +
            "from job_make " +
            "where 1=1" +
            "<if test='nameType!=null'>and nametype like concat('%',#{nameType})</if> " +
            "<if test='jobName!=null'> and jobname like concat('%',#{jobName},'%')</if>" +
            "</script>")
    List<JobMake> selectJobNameAndJobType(@Param("nameType") String nameType, @Param("jobName") String jobName);

    @Select("select distinct jobname from job_make where nametype = #{nameType}")
    List<JobMake> selectJobName(String nameType);

    @Insert("insert into job_make(jobname, nametype,  recentmaketime) " +
            "VALUES (#{jobName},#{nameType},#{recentMakeTime})")
    Integer insertJobMark(@Param("jobName") String jobName, @Param("nameType") String nameType, @Param("recentMakeTime") Date recentMakeTime);

    @Update("update job_make " +
            "set jobname=#{jobName},nametype=#{nameType},makeshift=#{makeShift}, recentmaketime=#{recentMakeTime} " +
            "where id = #{id}")
    Integer updateJobMark(@Param("id") int id, @Param("jobName") String jobName, @Param("nameType") String nameType, @Param("makeShift") String makeShift, @Param("recentMakeTime") Date recentMakeTime);

    @Delete("delete from job_make where id =#{id}")
    Integer deleteJobMark(int id);

    @Delete("truncate table job_make")
    Integer clearJobMark();

    @Update("update job_make " +
            "set recentmaketime=#{recentMakeTime} " +
            "where jobname=#{jobName} and nametype=#{nameType}")
    Integer updateJobMark2( @Param("jobName") String jobName, @Param("nameType") String nameType, @Param("recentMakeTime") Date recentMakeTime);

    @Select("select id,jobname,nametype,recentmaketime from job_make")
    List<JobMake> listJobMark();

    @Select("select id from job_make order by id desc limit 1")
    Integer selcetlastId();
}
